package com.sx.pipeline.ui.chat.personal

import android.content.DialogInterface
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.gyf.immersionbar.ImmersionBar
import com.hjq.bar.OnTitleBarListener
import com.hjq.bar.TitleBar
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.app.config.IntentKey
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActPersonalInfoBinding
import com.sx.pipeline.ui.chat.ChatVM
import io.rong.imkit.utils.PermissionCheckUtil
import io.rong.imkit.utils.RouteUtils
import io.rong.imlib.model.Conversation


/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 群聊个人资料
 */
@Route(path = RoutePath.Chat.CHAT_PERSONAL)
class PersonalInfoActivity :
    CYDataBindingBaseActivity<ActPersonalInfoBinding, ChatVM>(R.layout.act_personal_info),
    View.OnClickListener {
    @JvmField
    @Autowired(name = IntentKey.ID)
    var userId: Int? = 0

    override fun initData() {
        super.initData()
        // 设置状态栏字体颜色
        ImmersionBar.with(this)
            .fitsSystemWindows(true)
            .statusBarColor(com.sx.pipeline.R.color.color_0188ff)
            .statusBarDarkFont(false)
            .init()
        mBinding.setVariable(BR.onClick, this)
        mBinding.titleBar.setOnTitleBarListener(object : OnTitleBarListener {
            override fun onLeftClick(titleBar: TitleBar?) {
                super.onLeftClick(titleBar)
                finish()
            }
        })
        //如果是自己的个人信息则隐藏发送消息入口
//        if (mViewModel.mModel.getUserData()?.userUnitId?.toInt() == userId) {
//            mBinding.tvSend.visibility = View.GONE
//        }
        userId?.let { mViewModel.getRyPersonalInfo(it) }
        mBinding.titleBar.rightView.setOnClickListener {
            ARouter.getInstance().build(RoutePath.Chat.CHAT_REPORT)
                .withInt("type", 1)
                .withString("rId", userId.toString())
                .navigation()
        }
    }

    override fun initViewObservable() {
        super.initViewObservable()
        observe(mViewModel.contactInfoDataEvent) {
            Glide.with(this).load(it?.avatar).placeholder(R.mipmap.ic_default_head)
                .into(mBinding.ivAvatar)
            mBinding.tvName.text = it?.userName
            mBinding.sbGender.rightText = it?.sex
            mBinding.sbPhone.rightText = it?.phone
            mBinding.sbJob.rightText = it?.postName
            mBinding.sbDepart.rightText = it?.deptName
            mBinding.sbLeader.rightText = it?.prentPhone
            mBinding.sbLeaderPhone.rightText = it?.prentPhone
        }
    }

    override fun initListener() {
        super.initListener()
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_send -> {
                RouteUtils.routeToConversationActivity(
                    this,
                    Conversation.ConversationType.PRIVATE,
                    userId.toString()
                );

            }
        }
    }


}